﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
namespace BLL.Admin
{
    public class QuocGiaHelper
    {
        public static void Add_QuocGia(string TenQuocGia)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            tbl_DM_QuocGia quocgia = new tbl_DM_QuocGia();
            quocgia.Ten = TenQuocGia;
            db.tbl_DM_QuocGias.InsertOnSubmit(quocgia);
            db.SubmitChanges();
        }
        public static void Update_QuocGia(int QuocGiaId,string TenQuocGia)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            tbl_DM_QuocGia quocgia = db.tbl_DM_QuocGias.FirstOrDefault(k=>k.QuocGiaId==QuocGiaId);
            quocgia.Ten = TenQuocGia;            
            db.SubmitChanges();
        }
        public static tbl_DM_QuocGia Get_QuocGiaId(int QuocGiaId)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            tbl_DM_QuocGia quocgia = db.tbl_DM_QuocGias.FirstOrDefault(k => k.QuocGiaId == QuocGiaId);
            return quocgia;
        }
        public static IQueryable List_QuocGia_Search(string Ten)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            var query = from qg in db.tbl_DM_QuocGias
                        where qg.Ten.Contains(Ten)
                        orderby qg.Ten ascending
                        select new { 
                            qg.QuocGiaId,
                            qg.Ten,
                        };
            return query;
        }
        public static IQueryable List_QuocGia()
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            var query = from qg in db.tbl_DM_QuocGias
                        orderby qg.Ten ascending
                        select new
                        {
                            qg.QuocGiaId,
                            qg.Ten,
                        };
            return query;
        }
    }
}